package tuiLayer;
import controlLayer.*;
import modelLayer.*;
import java.util.*;

public class CustomerUI
{
    private CustomerCtr customerCtr;
  
    public CustomerUI(){
        customerCtr = new CustomerCtr();
    }
    
    public void start(){
        mainMenuCustomer();
    }
    
    private void mainMenuCustomer(){
        boolean stop=false;
        while(!stop){
            int choice = writeMainMenuCustomer();
            
            switch(choice){
                case 0:
                    stop = true;
                    break;             
                case 1:
                    createCustomer();
                    break;
                case 2:
                    findCustomer();
                    break;
                case 3:
                    updateCustomer();
                    break;
                case 4:
                    deleteCustomer();
                    break;
                default : System.out.println("Enter a valid choice");
                    
            }
        }
    }
    
    private int writeMainMenuCustomer(){
        Scanner keyboard = new Scanner(System.in);
        System.out.println("\n*****Customer menu*****");
        System.out.println("(0) Back");
        System.out.println("(1) Create customer");
        System.out.println("(2) Find customer");
        System.out.println("(3) Update customer");
        System.out.println("(4) Delete customer ");
        System.out.println("\nType your choice");
        int choice= keyboard.nextInt();
        return choice;
    }
    
    private void createCustomer(){
        Scanner keyboard = new Scanner(System.in);
        System.out.println("---Customer creation---");
        System.out.println();
        
        System.out.println("Enter customer's name:");
        String name = keyboard.nextLine();
        
        System.out.println("Enter customer's address:");
        String address = keyboard.nextLine();
        
        System.out.println("Enter customer's phone number:");
        String phoneNo = keyboard.nextLine();
        
        System.out.println("Enter customer's email:");
        String email = keyboard.nextLine();
        
        System.out.println("Enter customer group (gold/silver/bronze): ");
        String type = keyboard.nextLine();
        
        customerCtr.createCustomer(name, address, phoneNo, email,type);
        System.out.println("Customer successfully created!");
        
    }
    
    private void findCustomer(){
        Scanner keyboard = new Scanner(System.in);
         System.out.println("---Customer search---");
        System.out.println();
        System.out.println("Enter customers id:");
        int idC = keyboard.nextInt();
        
        Customer c =  customerCtr.findCustomer(idC);
        
        System.out.println();
        System.out.println("--------------------------------");
        System.out.println("ID:\t\t\t" + c.getId());
        System.out.println("Address:\t\t" + c.getAddress());
        System.out.println("Email:\t\t\t" + c.getEmail());
        System.out.println("Phone Number:\t\t" + c.getPhoneNo());
        System.out.println("Name:\t\t\t" + c.getName());
        System.out.println("Type:\t\t\t" + c.getType() );
        System.out.println("--------------------------------");
    }
    
    private void updateCustomer(){
        Scanner keyboard = new Scanner(System.in);
        System.out.println("---Customer update---");
        System.out.println();
        
        System.out.println("Enter customer's id:");
        int idC= keyboard.nextInt();
        keyboard.nextLine();
        
        System.out.println("Enter customer's name:");
        String name = keyboard.nextLine();
        
        System.out.println("Enter customer's address:");
        String address = keyboard.nextLine();
        
        System.out.println("Enter customer's phone number:");
        String phoneNo = keyboard.nextLine();
        
        System.out.println("Enter customer's email:");
        String email = keyboard.nextLine();
        
        System.out.println("Enter customer group (gold/silver/bronze): ");
        String type = keyboard.nextLine();
        
        customerCtr.updateCustomer(idC, name, address, phoneNo, email,type);
        System.out.println("Customer successfully updated!");
    }
    
    private void deleteCustomer(){
        Scanner keyboard = new Scanner(System.in);
        System.out.println("---Customer removal---");
        System.out.println();
        
        System.out.println("Enter the customer's id:");
        int idC = keyboard.nextInt();
        
        customerCtr.deleteCustomer(idC);
        System.out.println("Customer successfuly deleted!");
    }
}